//
//  FANPictureCollectionView.m
//  Weibo - OC
//
//  Created by user on 16/4/23.
//  Copyright © 2016年 user. All rights reserved.
//

#import "FANPictureCollectionView.h"
#import "FANPictureCell.h"
#import "FANStatusPicInfo.h"

@interface FANPictureCollectionView ()<UICollectionViewDataSource>



@end

static NSString *identifier = @"identifier";

@implementation FANPictureCollectionView

- (void)setPic_urls:(NSArray *)pic_urls{
    
    _pic_urls = pic_urls;
    
    [self reloadData];
}

- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout{
    
    if (self = [super initWithFrame:frame collectionViewLayout:layout]) {
        
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI{
    
    self.backgroundColor = [UIColor clearColor];
    
    self.dataSource = self;
    
    [self registerClass:[FANPictureCell class] forCellWithReuseIdentifier:identifier];
    
    UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout *)self.collectionViewLayout;
    
    flowLayout.itemSize = CGSizeMake(FANPictureWH, FANPictureWH);
    
    flowLayout.minimumInteritemSpacing = FANPictureMargin;
    
    flowLayout.minimumLineSpacing = FANPictureMargin;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return self.pic_urls.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    FANPictureCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier: identifier forIndexPath:indexPath];
    
    FANStatusPicInfo *model = self.pic_urls[indexPath.item];
    
    cell.imageString = model.thumbnail_pic;
    
    return  cell;
}

@end
